package com.example.library.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: asus
 * Date: 2024-12-28
 * Time: 17:33
 */
@Component
@Aspect
@Slf4j
public class TimeAspect {
    /**
     *
     * @param joinPoint 目标方法
     * @return
     */
    @Around("execution(* com.example.library.controller.*.*(..))")
    public Object timeCost(ProceedingJoinPoint joinPoint) throws Throwable {
        long start = System.currentTimeMillis();
        Object result = joinPoint.proceed();//让目标方法执行
        long end = System.currentTimeMillis();
        log.info(joinPoint.getSignature() + "消耗时间:" + (end - start) + "ms");
        return result;
    }
}
